#include "MainMenu.h"

MainMenu::MainMenu (void)
{
}

MainMenu::MainMenu (DXDevice* Device, UINT ScrnWidth, UINT ScrnHeight)
{
	Init (Device, ScrnWidth, ScrnHeight);
}

MainMenu::~MainMenu (void)
{
	if (PlayGame)
		delete PlayGame;
	if (Quit)
		delete Quit;
	if (Title)
		delete Title;
	if (Bckgrnd)
		delete Bckgrnd;
}

BOOL MainMenu::Init (DXDevice* Device, UINT ScrnWidth, UINT ScrnHeight)
{
	BOOL Success = FALSE;
	SelText = PLAY_GAME;

	PlayGame = new DXText(Device->GetDrawDevice(), TEXT_SIZE, L"Times New Roman", COLOR(0, 255, 0, 255));
	PlayGame->SetTextLocation((ScrnWidth / 2) - 70, (ScrnHeight / 2) + 25);
	PlayGame->SetText("Play Game");
	Quit = new DXText(Device->GetDrawDevice(), TEXT_SIZE, L"Times New Roman", COLOR(255, 0, 0, 255));
	Quit->SetTextLocation((ScrnWidth / 2) - 35, (ScrnHeight / 2) + 100);
	Quit->SetText("Quit");
	Title = new DXText(Device->GetDrawDevice(), 80, L"Miriam Fixed", COLOR(50, 0, 255, 255));
	Title->SetTextLocation((ScrnWidth / 2) - 340, 50);
	Title->SetText("Space Commando");
	Bckgrnd = new DXSprite(Device->GetDrawDevice(), Device->GetSpriteDevice(), L"Bckgrnd.png", D3DXVECTOR3(0.0f, 0.0f, 1.0f));

	return Success;
}

GameState MainMenu::Update (DXKeyboard & Keyboard)
{
	GameState State = MAIN_MENU;

	switch (SelText)
	{
		case PLAY_GAME:
			{
				if (Keyboard.IsKeyDown(DIK_DOWN))
				{
					SelText = QUIT;
					PlayGame->SetColor(COLOR(255, 0, 0, 255));
					Quit->SetColor(COLOR(0, 255, 0, 255));
				}
				else if (Keyboard.IsKeyDown(DIK_RETURN))
					State = IN_GAME;
			} break;

		case QUIT:
			{
				if (Keyboard.IsKeyDown(DIK_UP))
				{
					SelText = PLAY_GAME;
					PlayGame->SetColor(COLOR(0, 255, 0, 255));
					Quit->SetColor(COLOR(255, 0, 0, 255));
				}
				else if (Keyboard.IsKeyDown(DIK_RETURN))
					State = EXIT;
			} break;
	}

	return State;
}

void MainMenu::Draw (void)
{
	PlayGame->Draw();
	Quit->Draw();
	Title->Draw();
	Bckgrnd->Draw();
}